proc do_translate_money {} {

    global prefix
    global prompt
    global len
    global newlist
    global gender
    global numbers
    global digits

    set newlist [split $digits .]
    set check {}
 
    set gender m
   
    do_whole_part

    if {$len == 1 } {
       switch -regexp $numbers(tens) {
           {0} { }
           {1} {lappend prompt "[set prefix]_dollar.au"}
           {[2-4]} {lappend prompt "[set prefix]_2-4_dollars.au"}
           {[5-9]} {lappend prompt "[set prefix]_5-20_dollars.au"}
       }
    } else {
       switch -regexp $numbers(tens) {
           {[0-9]*[0|2-9][2-4]} {lappend prompt "[set prefix]_2-4_dollars.au"}
           {[0-9]*[2-9][1]}     {lappend prompt "[set prefix]_dollar.au"}
           default              {lappend prompt "[set prefix]_5-20_dollars.au"}
       }
    }

    set gender f
    do_decimal_part
 
    if {[string length [lindex $newlist 1]] == 1} {
        switch -regexp [lindex $newlist 1] {
                {0}     { }
                default {lappend prompt "[set prefix]_5-20_cents.au"}
        }
    } else {
        switch -regexp [lindex $newlist 1] {
                {00}           { }
                {[0|2-9][1]}   {lappend prompt "[set prefix]_cent.au"}
                {[0|2-9][2-4]} {lappend prompt "[set prefix]_2-4_cents.au"}
                default        {lappend prompt "[set prefix]_5-20_cents.au"}
        }
    } 
    set prompt [linsert $prompt 0 "_you_have.au"]
    return $prompt
}

proc do_translate_time {} {
 
    global prefix
    global len
    global prompt
    global newlist
    global numbers
    global gender
    global digits     

    set prompt ""

    set hours [expr { $digits / 3600 }]
    set minutes [expr {int([expr { $digits % 3600} / 60])}]
    set seconds [expr { $digits % 60}]
 
    puts "\nDEBUG: ru_translate: do_translate_time: hours = $hours, minutes = $minutes, seconds = $seconds"

    #if {[string length $minutes] == 1 } {
    #       set minutes 0$minutes
    #}
 

    set newlist [list $hours $minutes $seconds]
    set gender m

     do_whole_part
     if {$len == 1 } {
              switch -regexp $numbers(tens) {
                  {0} { }
                  {1} {lappend prompt "[set prefix]_hour.au"}
                  {[2-4]} {lappend prompt "[set prefix]_2-4_hours.au"}
                  {[5-9]} {lappend prompt "[set prefix]_5-20_hours.au"}
              }
     } else {
              switch -regexp $numbers(tens) {
                  {[0-9]*[0|2-9][2-4]} {lappend prompt "[set prefix]_2-4_hours.au"}
                  {[0-9]*[2-9][1]}     {lappend prompt "[set prefix]_hour.au"}
                  default              {lappend prompt "[set prefix]_5-20_hours.au"}
              }
     }

     set list_index_1 [lindex $newlist 1] 

     set gender f
 
     do_decimal_part 

 
     if {[string length [lindex $newlist 1]] == 1} {
           switch -regexp [lindex $newlist 1] {
                         {0}     { }
                         default {lappend prompt "[set prefix]_5-20_minutes.au"}
           }
     } else {
           switch -regexp [lindex $newlist 1] {
                         {00}           { }
                         {[0|2-9][1]}   {lappend prompt "[set prefix]_minute.au"}
                         {[0|2-9][2-4]} {lappend prompt "[set prefix]_2-4_minutes.au"}
                         default        {lappend prompt "[set prefix]_5-20_minutes.au"}
           }
     }

    
     do_seconds

     if {[string length [lindex $newlist 2]] == 1} {
           switch -regexp [lindex $newlist 2] {
                         {0}     { }
                         default {lappend prompt "[set prefix]_5-20_seconds.au"}
           }
     } else {
           switch -regexp [lindex $newlist 2] {
                         {00}           { }
                         {[0|2-9][1]}   {lappend prompt "[set prefix]_second.au"}
                         {[0|2-9][2-4]} {lappend prompt "[set prefix]_2-4_seconds.au"}
                         default        {lappend prompt "[set prefix]_5-20_seconds.au"}
           }
     } 


    set prompt [linsert $prompt 0 "_you_have.au"]
    return $prompt
}


proc do_tens {} {
    global prompt
    global prefix
    global numbers
    global len
    global gender


    if {$numbers(tens) != 0} {
            if {[string length $numbers(tens)] == 1} {
		       switch -regexp $numbers(tens) {
			   {0} { }
			   {1-2} {lappend prompt "[set prefix]_$numbers(tens)_[set gender].au"}
			   default {lappend prompt "[set prefix]_$numbers(tens).au"}
		       }
	    } else { set seperate [split $numbers(tens) ""]
		        switch -regexp $numbers(tens) {
			    {00}         { }
                            {[0][1-2]}   {lappend prompt "[set prefix]_[lindex $seperate 1]_[set gender].au"}
                            {[0][3-9]}   {lappend prompt "[set prefix]_[lindex $seperate 1].au"}
                            {[1][1-9]}   {lappend prompt "[set prefix]_$numbers(tens).au"}
                            {[2-9][1-2]} {lappend prompt "[set prefix]_$numbers(tens)_[set gender].au"}
                            {[1-9][0]}   {lappend prompt "[set prefix]_[lindex $seperate 0]0.au"}
                            default      {lappend prompt "[set prefix]_[lindex $seperate 0]0.au" "[set prefix]_[lindex $seperate 1].au"}
		        }
	    }
    }
    return 0
}

proc do_hundreds {} {
    global prompt
    global prefix
    global numbers

 
    if {$numbers(hundreds) == 0} {
	return 0
    } else {
	lappend prompt "[set prefix]_$numbers(hundreds)00.au"
    }
    return 0
}

proc do_thousands {} {
    global prompt
    global prefix
    global numbers
    global len

    if {$numbers(thousands) == 0} {
	lappend prompt "[set prefix]_5-20_thousand.au"
    } else {
	    if {$len == 4} {
		      switch -regexp $numbers(thousands) {
			  1     {lappend prompt "[set prefix]_thousand.au"}
			  2     {lappend prompt "[set prefix]_$numbers(thousands)_f.au" "[set prefix]_2-4_thousand.au"}
		        {[3-4]} {lappend prompt "[set prefix]_$numbers(thousands).au" "[set prefix]_2-4_thousand.au"}
		        default {lappend prompt "[set prefix]_$numbers(thousands).au" "[set prefix]_5-20_thousand.au"}
		      }
	    } else {
                      set seperate [split $numbers(thousands) ""]
		      switch -regexp $numbers(thousands) {
			  {00}       {lappend prompt "[set prefix]_5-20_thousand.au"}
			  {01}       {lappend prompt "[set prefix]_thousand.au"}
			  {02}       {lappend prompt lappend prompt "[set prefix]_[lindex $seperate 1]_f.au" "[set prefix]_2-4_thousand.au"}
			  {[0][3-4]} {lappend prompt lappend prompt "[set prefix]_[lindex $seperate 1].au" "[set prefix]_2-4_thousand.au"}
			  {[0][5-9]} {lappend prompt lappend prompt "[set prefix]_[lindex $seperate 1].au" "[set prefix]_5-20_thousand.au"}
			  {[1-9][0]} {lappend prompt "[set prefix]_[lindex $seperate 0]0.au" "[set prefix]_5-20_thousand.au"}
			  {[1][1-9]} {lappend prompt "[set prefix]_$numbers(thousands).au" "[set prefix]_5-20_thousand.au"}
			  {[2-9][1]} {lappend prompt "[set prefix]_$numbers(thousands)_f.au" "[set prefix]_thousand.au"}
			  {[2-9][2]} {lappend prompt "[set prefix]_$numbers(thousands)_f.au" "[set prefix]_2-4_thousand.au"}
			  {[2-9][3-4]} {lappend prompt "[set prefix]_[lindex $seperate 0]0.au" "[set prefix]_[lindex $seperate 1].au" "[set prefix]_2-4_thousand.au"}
			  {[2-9][5-9]} {lappend prompt "[set prefix]_[lindex $seperate 0]0.au" "[set prefix]_[lindex $seperate 1].au" "[set prefix]_5-20_thousand.au"}
		      }
	    }
    }

    return 0
}

proc do_hthousands {} {
    global prompt
    global prefix
    global numbers

    set hlen [string length $numbers(hthousands)]
    lappend prompt "[set prefix]_$numbers(hthousands)00.au"

    return 0
}

proc do_whole_part {} {
    global amt
    global prefix
    global prompt
    global numbers
    global len
    global newlist

    set numbers(tens) ""
    set numbers(hundreds) ""
    set numbers(thousands) ""
    set numbers(hthousands) ""

    set len [string length [lindex $newlist 0]]

    set seperate [split [lindex $newlist 0] ""]


    switch -regexp $len {
	{1} {set numbers(tens) [lindex $seperate 0]
	}
	{2} {set numbers(tens) [join [list [lindex $seperate 0] [lindex $seperate 1]] "" ]
	}
	{3} {set numbers(hundreds) [lindex $seperate 0]
	     set numbers(tens) [join [list [lindex $seperate 1] [lindex $seperate 2]] "" ]
	}
	{4} {set numbers(thousands) [lindex $seperate 0]
             set numbers(hundreds) [lindex $seperate 1]
	     set numbers(tens) [join [list [lindex $seperate 2] [lindex $seperate 3]] "" ]
	}
	{5} {set numbers(thousands) [join [list [lindex $seperate 0] [lindex $seperate 1]] "" ]
             set numbers(hundreds) [lindex $seperate 2]
	     set numbers(tens) [join [list [lindex $seperate 3] [lindex $seperate 4]] "" ]
	}
	{6} {set numbers(hthousands) [lindex $seperate 0]
             set numbers(thousands) [join [list [lindex $seperate 1] [lindex $seperate 2]] "" ]
             set numbers(hundreds) [lindex $seperate 3]
	     set numbers(tens) [join [list [lindex $seperate 4] [lindex $seperate 5]] "" ]
	}
    }

    foreach index {hthousands thousands hundreds tens} {

       if {[string compare $numbers($index) ""] != 0} {

           do_$index
       }
   }
   return 0
}

proc do_decimal_part {} {
   global newlist
   global prompt
   global prefix
   global gender

   #if {( [lindex $newlist 0] > 0 ) && ( [lindex $newlist 1] > 0 ) } {
   #     lappend prompt "[set prefix]_and.au"
   #}

   if {[string length [lindex $newlist 1]] == 1} {
        switch -regexp [lindex $newlist 1] {
                                             {0} { }
	                                     default {lappend prompt "[set prefix]_[lindex $newlist 1].au"}
        }
   } else { set seperate [split [lindex $newlist 1] ""]
        switch -regexp [lindex $newlist 1] {
		      {00}         { }
		      {[0][1-2]}   {lappend prompt "[set prefix]_[lindex $seperate 1]_[set gender].au"}
		      {[0][3-9]}   {lappend prompt "[set prefix]_[lindex $seperate 1].au"}
		      {[1][1-9]}   {lappend prompt "[set prefix]_[lindex $newlist 1].au"}
		      {[2-9][1-2]} {lappend prompt "[set prefix]_[lindex $newlist 1]_[set gender].au"}
		      {[1-9][0]}   {lappend prompt "[set prefix]_[lindex $seperate 0]0.au"}
		      default      {lappend prompt "[set prefix]_[lindex $seperate 0]0.au" "[set prefix]_[lindex $seperate 1].au"}
        }
   }

   return 0
}

proc do_seconds {} {
   global newlist
   global prompt
   global prefix
   global gender

   if {( [lindex $newlist 1] > 0 ) && ( [lindex $newlist 2] > 0 ) } {
        lappend prompt "[set prefix]_and.au"
   }
    
   if {[string length [lindex $newlist 2]] == 1} {
        switch -regexp [lindex $newlist 2] {
                                             {0} { }
                                             default {lappend prompt "[set prefix]_[lindex $newlist 2].au"}
        }
   } else { set seperate [split [lindex $newlist 2] ""]
        switch -regexp [lindex $newlist 2] {
                      {00}         { }
                      {[0][1-2]}   {lappend prompt "[set prefix]_[lindex $seperate 1]_[set gender].au"}
                      {[0][3-9]}   {lappend prompt "[set prefix]_[lindex $seperate 1].au"}
                      {[1][1-9]}   {lappend prompt "[set prefix]_[lindex $newlist 2].au"}
                      {[2-9][1-2]} {lappend prompt "[set prefix]_[lindex $newlist 2]_[set gender].au"}
                      {[1-9][0]}   {lappend prompt "[set prefix]_[lindex $seperate 0]0.au"}
                      default      {lappend prompt "[set prefix]_[lindex $seperate 0]0.au" "[set prefix]_[lindex $seperate 1].au"}
        }
   }

   return 0
}

proc translate {str} {

    global prompt
    global digits
    global prefix

    set digits {}
    set prompt {}
    set prefix {}
    set percentExists 0
    set check {} 
    set char {}

    foreach char [split $str {}] { 
       if {$char == "%"} {
           set percentExists 1
           continue
       }
       if {$percentExists} {
           append check $char
           set percentExists 0
       } else {
           append digits $char
       }
    }
    
    switch -- $check {
       {a}   { 
              do_translate_money 
             }
       {t}   {
              do_translate_time 
             }
    }

 set str {}
 
 return $prompt
}

